package cn.edu.buaa.nlsde.grid.Structure;

import java.util.*;

public class Global
{
	public List<Grid> grids;

	public Global()
	{
		grids=new ArrayList<Grid>();
	}
	public Global(List<Grid> grids)
	{
		this.grids=grids;
	}
	
	public List<Grid> getGrids()
	{
		return grids;
	}
	public Grid getGrid(String gridName)
	{
		for (int i=0;i<grids.size();i++)
		{
			Grid grid=(Grid)grids.get(i);
			if((grid.getName()).equals(gridName))
			{
				return grid;
			}
		}
		return null;
	}

	public List<Cluster> getClusters(String gridName)
	{
		List<Cluster> clusters=new ArrayList<Cluster>();
		for (int i=0;i<grids.size();i++)
		{
			Grid grid=(Grid)grids.get(i);
			if((grid.getName()).equals(gridName))
			{
				clusters=grid.getClusters();
				break;
			}
		}
		return clusters;
	}
	
	public List<Host> getHosts(String gridName,String clusterName)
	{
		List<Host> hosts=new ArrayList<Host>();
		List<Cluster> clusters=getClusters(gridName);
		for (int i=0;i<clusters.size();i++)
		{
			Cluster cluster=(Cluster)clusters.get(i);
			if((cluster.getName()).equals(clusterName))
			{
				hosts=cluster.getHosts();
				break;
			}
		}
		return hosts;
	}

	public List<Metric> getMetrics(String gridName,String clusterName,String hostName)
	{
		List<Metric> metrics=new ArrayList<Metric>();
		List<Host> hosts=getHosts(gridName,clusterName);
		for (int i=0;i<hosts.size();i++)
		{
			Host host=(Host) hosts.get(i);
			if ((host.getName()).equals(hostName))
			{
				metrics=host.getMetrics();
				break;
			}
		}
		return metrics;
	}
}